package cn.zians.dao;

import cn.zians.domain.Employee;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 员工dao接口
 *
 * @Date 2020.8.27 10:36
 */
@Repository
public interface IEmployeeDao {
    /**
     * 查询所有员工
     *
     * @return
     */
    @Select("select * from Employee")
    List<Employee> findAll();

    /***
     * 添加员工信息
     * @param employee
     */
    @Insert("insert into Employee (name,age,sex,address) values (#{name},#{age},#{sex},#{address})")
    void addEmloyee(Employee employee);

    /**
     * 删除员工辛
     *
     * @param id
     */
    @Delete("delete from Employee where id = #{id}")
    void deleteEmloyee(Integer id);

    /**
     * 更新员工辛
     *
     * @param employee
     */
    @Update("<script>update Employee " +
            "<if test=\"age!=null\">set age= #{age} </if>" +
            "<if test=\"address!=null\">, address= #{address} </if>" +
            "<if test=\"sex!=null\">, sex= #{sex} </if>" +
            "<if test=\"name!=null\">, name= #{name} </if>" +
            "<if test=\"id!=null\">where id = #{id} </if></script>")
    void updateEmloyee(Employee employee);
}
